package cn.mill.core;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import cn.mill.common.Context;
import cn.mill.common.Listener;

public class DefaultListener implements Listener {
	
	private static Logger logger = LoggerFactory.getLogger(DefaultListener.class);
	
	public static final Listener INSTANCE = new DefaultListener();
	
	@Override
	public void notify(Context invoke, long time) {
		logger.info("invoke [" + invoke.getTip() + "] 用时 [" + time + " ms]");
		try {
			Runtime runtime = Runtime.getRuntime();
			logger.debug("处理器的数目" + runtime.availableProcessors());
			logger.debug("空闲内存量：" + runtime.freeMemory() / 1024L / 1024L + "MB");
			logger.debug("使用的最大内存量：" + runtime.maxMemory() / 1024L / 1024L + "MB");
			logger.debug("内存总量：" + runtime.totalMemory() / 1024L / 1024L + "MB");
			logger.debug("使用内存量：" + (runtime.totalMemory() - runtime.freeMemory()) / 1024L / 1024L + "MB");
		} catch (Exception e) {
			logger.error("DefaultListener", e);
		}
	}
	
}
